﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using NOAH.CMS.Repository;
using NOAH.CMS.Cache;


public partial class admin_Modules_Common_Themes_Default : System.Web.UI.Page
{
    protected void AddOrEdit(object sender, EventArgs e)
    {
        using (ConfigRepository configRepository = new ConfigRepository())
        {
            bool add = false;
            Config themeConfig = configRepository.GetConfigByKey(ConfigKey.Theme);
            if (themeConfig == null)
            {
                themeConfig = new Config();
                themeConfig.Key = ConfigKey.Theme;
                add = true;
            }
            if (chkTheme1.Checked) themeConfig.Value = "default";
            if (chkTheme2.Checked) themeConfig.Value = "red";
            if (add) configRepository.Add(themeConfig);
            configRepository.SubmitChanges();
            new ConfigCacheLayer().InvalidateCache();
            Util.ShowMessage(Constants.UPDATE_SUCCESS);
            X.Msg.Hide();
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (X.IsAjaxRequest) return;
        using (ConfigRepository configRepository = new ConfigRepository())
        {
            bool add = false;
            Config themeConfig = configRepository.GetConfigByKey(ConfigKey.Theme);
            if (themeConfig != null)
            {
                if (themeConfig.Value == "default")
                    chkTheme1.Checked = true;
                else
                {
                    chkTheme2.Checked = true;

                }
            }
            else
            {
                chkTheme1.Checked = true;
            }
        }
    }
}